#include <iostream>
#include <iomanip>
using namespace std;
#define ROW 9
#define COL 9
#define ROWS ROW + 2
#define COLS COL + 2
#define EASY_COUNT 10
void InitBoard(char arr[ROWS][COLS], int rows, int cols, char set)
{
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            arr[i][j] = set;
        }
    }
}
void Displayboard(char arr[ROWS][COLS], int row, int col)
{
    cout << "------扫雷游戏------" << endl;
    for (int j = 0; j <= col; j++)
    {
        cout << setw(2) << setfill(' ') << j << " ";
    }
    cout << endl;
    for (int i = 1; i <= row; i++)
    {
        cout << setw(2) << setfill(' ') << i << " ";
        for (int j = 1; j <= col; j++)
        {
            cout << setw(2) << setfill(' ') << arr[i][j] << " ";
        }
        cout << endl;
    }
    cout << "------扫雷游戏------" << endl;
}
void SetMine(char arr[ROWS][COLS], int row, int col)
{
    int count = EASY_COUNT;
    while (count)
    {
        int x = rand() % row + 1;
        int y = rand() % col + 1;
        if (arr[x][y] == '0')
        {
            arr[x][y] = '1';
            count--;
        }
    }
}
int GetMine(char mine[ROWS][COLS], int x, int y)
{
    return (mine[x - 1][y] + mine[x - 1][y - 1] + mine[x][y - 1] + mine[x + 1][y - 1] + mine[x + 1][y] +
            mine[x + 1][y + 1] + mine[x][y + 1] + mine[x - 1][y + 1] - 8 * '0');
}
void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
    int x = 0;
    int y = 0;
    int win = 0;
    while (win < (row * col - EASY_COUNT))
    {
        cout << "请输入要排查的雷的坐标: >";
        cin >> x >> y;
        if (x >= 1 && x <= row && y >= 1 && y <= col)
        {
            if (show[x][y] == '*')
            {
                if (mine[x][y] == '1')
                {
                    cout << "很遗憾, 你被炸死了! " << endl;
                    Displayboard(mine, ROW, COL);
                    break;
                }
                else
                {
                    int count = GetMine(mine, x, y);
                    show[x][y] = count + '0';
                    Displayboard(show, ROW, COL);
                    win++;
                }
            }
            else
            {
                cout << "该坐标已经被排查过了, 请重新输入: " << endl;
            }
        }
        else
        {
            cout << "坐标非法, 请重新输入: " << endl;
        }
    }
    if (win == (row * col - EASY_COUNT))
    {
        cout << "恭喜您, 排雷成功！ " << endl;
        Displayboard(mine, ROW, COL);
    }
}